package com.example.exam.controller;

import com.example.exam.entity.Assist;
import com.example.exam.entity.Role;
import com.example.exam.entity.Teacher;
import com.example.exam.service.AssistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * (Assist)表控制层
 *
 * @author makejava
 * @since 2021-09-07 11:30:53
 */
@RestController
@RequestMapping("/assist")
public class AssistController {
    /**
     * 服务对象
     */
    @Autowired
    private AssistService assistService;


    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public Assist selectOne(HttpSession session) {
        Integer id = (Integer) session.getAttribute("userId");
        return this.assistService.queryById(id);
    }

    @RequestMapping("/updateOne")
    public Assist updateOne(Assist assist, HttpSession session) {
        Integer id = (Integer) session.getAttribute("userId");
        Assist assist1 = assistService.queryById(id);
        if (assist.getAssname() != null) {
            assist1.setAssname(assist.getAssname());
        }
        if (assist.getInstutite() != null) {
            assist1.setInstutite(assist.getInstutite());
        }
        if (assist.getTel() != null) {
            assist1.setTel(assist.getTel());
        }
        if (assist.getEmail() != null) {
            assist1.setEmail(assist.getEmail());
        }
        return this.assistService.update(assist1);
    }
}